<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>polynomial</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" />
    <link rel="prev" href="polyaft.html" title="polyaft" />
    <link rel="next" href="port.html" title="port" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">polynomial</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="polyaft.html">Prev</a> </td>
          <th width="60%" align="center">Orchestra Opcodes and Operators</th>
          <td width="20%" align="right"> <a accesskey="n" href="port.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry">
      <a id="polynomial"></a>
      <div class="titlepage"></div>
      <a id="IndexPolynomial" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">polynomial</span>
        </h2>
        <p>polynomial — 
      Efficiently evaluates a polynomial of arbitrary order.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp134987152"></a>
        <h2>Description</h2>
        <p>
      The <span class="emphasis"><em>polynomial</em></span> opcode calculates a polynomial with a single a-rate input variable.  The polynomial is a sum of any number of terms in the form <span class="emphasis"><em>kn*x^n</em></span> where <span class="emphasis"><em>kn</em></span> is the nth coefficient of the expression.  These coefficients are k-rate values.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp135055056"></a>
        <h2>Syntax</h2>
        <pre class="synopsis">aout <span class="command"><strong>polynomial</strong></span> ain, k0 [, k1 [, k2 [...]]]</pre>
      </div>
      <div class="refsect1">
        <a id="idp135057280"></a>
        <h2>Performance</h2>
        <p>
      <span class="emphasis"><em>ain</em></span> --  the input signal used as the independent variable of the polynomial ("x").
    </p>
        <p>
      <span class="emphasis"><em>aout</em></span> --  the output signal ("y").
    </p>
        <p>
      <span class="emphasis"><em>k0, k1, k2, ...</em></span> --  the coefficients for each term of the polynomial.
    </p>
        <p>
      If we consider the input parameter <span class="emphasis"><em>ain</em></span> to be "x" and the output <span class="emphasis"><em>aout</em></span> to be "y", then the <span class="emphasis"><em>polynomial</em></span> opcode calculates the following equation:
      </p>
        <div class="literallayout">
          <p><br />
        y = k0 + k1*x + k2*x^2 + k3*x^3 + ...<br />
      </p>
        </div>
        <p>
    </p>
      </div>
      <div class="refsect1">
        <a id="idp135063472"></a>
        <h2>Examples</h2>
        <p>
      Here is an example of the polynomial opcode. It uses the file <a class="ulink" href="examples/polynomial.csd" target="_top"><em class="citetitle">polynomial.csd</em></a>.
      </p>
        <div class="example">
          <a id="idp135065328"></a>
          <p class="title">
            <strong>Example 638. Example of the polynomial opcode.</strong>
          </p>
          <div class="example-contents">
            <p>See the sections <a class="link" href="UsingRealTime.html" title="Real-Time Audio"><em class="citetitle">Real-time Audio</em></a> and <a class="link" href="CommandFlags.html" title="Csound command line"><em class="citetitle">Command Line Flags</em></a> for more information on using command line flags.</p>
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
<span class="comment">; Select audio/midi flags here according to platform</span>
-odac  <span class="comment">;;;realtime audio</span>
<span class="comment">;-iadc    ;;;uncomment -iadc if realtime audio input is needed too</span>
<span class="comment">; For Non-realtime ouput leave only the line below:</span>
<span class="comment">; -o polynomial.wav -W ;;; for file output any platform</span>
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>

<span class="ohdr">sr</span> <span class="op">=</span> 44100
<span class="ohdr">ksmps</span> <span class="op">=</span> 32
<span class="ohdr">nchnls</span> <span class="op">=</span> 2
<span class="ohdr">0dbfs</span>  <span class="op">=</span> 1

<span class="comment">; The polynomial y=x^n where n is odd always produces a curve</span>
<span class="comment">; that traverses the range [-1, 1] when the input is within</span>
<span class="comment">; the same range.  Therefore, we can use one of these curves</span>
<span class="comment">; to make a nonlinear phasor that repeatedly reads a table </span>
<span class="comment">; from beginning to end like a linear phasor (maintaining </span>
<span class="comment">; continuity) but that distorts the waveform in the table.</span>

<span class="oblock">instr</span> 4	<span class="comment">; This instrument demonstrates phase distortion with x^3</span>

idur   <span class="op">=</span> p3
iamp   <span class="op">=</span> p4
ifreq  <span class="op">=</span> p5
itable <span class="op">=</span> p6
	
aenv <span class="opc">linseg</span> 0, .001, 1.0, idur <span class="op">-</span> .051, 1.0, .05, 0	<span class="comment">; declicking envelope</span>
aosc <span class="opc">phasor</span> ifreq					<span class="comment">; create a linear phasor</span>
apd  <span class="opc">polynomial</span> aosc, 0, 0, 0, 1			<span class="comment">; distort the phasor with x^3</span>
aout <span class="opc">tablei</span> apd, itable, 1				<span class="comment">; read a sine table with the nonlinear phasor</span>
     <span class="opc">outs</span> aenv<span class="op">*</span>aout<span class="op">*</span>iamp, aenv<span class="op">*</span>aout<span class="op">*</span>iamp
		
<span class="oblock">endin</span>

<span class="oblock">instr</span> 5	<span class="comment">; This instrument demonstrates phase distortion with x^11</span>

idur   <span class="op">=</span> p3
iamp   <span class="op">=</span> p4
ifreq  <span class="op">=</span> p5
itable <span class="op">=</span> p6

aenv <span class="opc">linseg</span> 0, .001, 1.0, idur <span class="op">-</span> .051, 1.0, .05, 0	<span class="comment">; declicking envelope</span>
aosc <span class="opc">phasor</span> ifreq					<span class="comment">; create a linear phasor</span>
apd  <span class="opc">polynomial</span> aosc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 <span class="comment">; distort the phasor with x^11</span>
aout <span class="opc">tablei</span> apd, itable, 1				<span class="comment">; read a sine table with the nonlinear phasor</span>
     <span class="opc">outs</span> aenv<span class="op">*</span>aout<span class="op">*</span>iamp, aenv<span class="op">*</span>aout<span class="op">*</span>iamp
		
<span class="oblock">endin</span>

<span class="oblock">instr</span> 6 <span class="comment">; This instrument crossfades between a pure sine and one distorted with x^11</span>

idur   <span class="op">=</span> p3
iamp   <span class="op">=</span> p4
ifreq  <span class="op">=</span> p5
itable <span class="op">=</span> p6
	
aenv	<span class="opc">linseg</span>	0, .001, 1.0, idur <span class="op">-</span> .051, 1.0, .05, 0	<span class="comment">; declicking envelope</span>
aosc	<span class="opc">phasor</span>	ifreq					<span class="comment">; create a linear phasor</span>
aout3	<span class="opc">tablei</span>	aosc, itable, 1				<span class="comment">; read a sine table without the linear phasor</span>
apd11	<span class="opc">polynomial</span> aosc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 <span class="comment">; distort the phasor with x^11</span>
aout11	<span class="opc">tablei</span>	apd11, itable, 1			<span class="comment">; read a sine table with the nonlinear phasor</span>
kamount	<span class="opc">linseg</span>	1.0, 0.05, 0.9, 1.0, 0.0		<span class="comment">; crossfade between two outputs</span>
aout	<span class="op">=</span> aout3<span class="op">*</span>kamount <span class="op">+</span> aout11<span class="op">*</span>(1.0 <span class="op">-</span> kamount)
        <span class="opc">outs</span> aenv<span class="op">*</span>aout<span class="op">*</span>iamp, aenv<span class="op">*</span>aout<span class="op">*</span>iamp	
	
<span class="oblock">endin</span>
<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>
<span class="stamnt">f</span>1 0 16385 10 1	<span class="comment">; sine wave</span>

<span class="comment">; descending "just blues" scale</span>

<span class="stamnt">t</span> 0 100
<span class="stamnt">i</span>4 0 .333 .7 512     1
<span class="stamnt">i</span>. + .    .  448
<span class="stamnt">i</span>. + .    .  384
<span class="stamnt">i</span>. + .    .  360
<span class="stamnt">i</span>. + .    .  341.33
<span class="stamnt">i</span>. + .    .  298.67
<span class="stamnt">i</span>. + 2    .  256
<span class="stamnt">s</span>

<span class="stamnt">t</span> 0 100
<span class="stamnt">i</span>5 0 .333 .7 512     1
<span class="stamnt">i</span>. + .    .  448
<span class="stamnt">i</span>. + .    .  384
<span class="stamnt">i</span>. + .    .  360
<span class="stamnt">i</span>. + .    .  341.33
<span class="stamnt">i</span>. + .    .  298.67
<span class="stamnt">i</span>. + 2    .  256
<span class="stamnt">s</span>

<span class="stamnt">t</span> 0 100
<span class="stamnt">i</span>6 0 .333 .7 512     1
<span class="stamnt">i</span>. + .    .  448
<span class="stamnt">i</span>. + .    .  384
<span class="stamnt">i</span>. + .    .  360
<span class="stamnt">i</span>. + .    .  341.33
<span class="stamnt">i</span>. + .    .  298.67
<span class="stamnt">i</span>. + 2    .  256

<span class="stamnt">e</span>

<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />
    </p>
      </div>
      <div class="refsect1">
        <a id="idp135069616"></a>
        <h2>See Also</h2>
        <p>
      <a class="link" href="chebyshevpoly.html" title="chebyshevpoly"><em class="citetitle">chebyshevpoly</em></a>, 
      <a class="link" href="mac.html" title="mac"><em class="citetitle">mac</em></a>
      <a class="link" href="maca.html" title="maca"><em class="citetitle">maca</em></a>
    </p>
      </div>
      <div class="refsect1">
        <a id="idp135073488"></a>
        <h2>Credits</h2>
        <p>
      </p>
        <table border="0" summary="Simple list" class="simplelist">
          <tr>
            <td>Author: Anthony Kozar</td>
          </tr>
          <tr>
            <td>January 2008</td>
          </tr>
        </table>
        <p>
    </p>
        <p>New in Csound version 5.08</p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="polyaft.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="OpcodesTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="port.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">polyaft </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> port</td>
        </tr>
      </table>
    </div>
  </body>
</html>
